<!-- 驶入禁入围栏 -->
<template>
  <a-modal
    :visible="visible"
    @cancel="onClose"
    :title="pageTlt"
    :mask-closable="false"
    :align-center="false"
    class="modal-dialog-wrapper"
    unmount-on-close
    top="30px"
    width="85vw"
    okText="确认"
  >
    <div style="max-height: 85vh">
      <a-tabs v-model="activeTabsKey" default-active-key="1" @change="tabsChangeFn">
        <a-tab-pane key="1" title="待处理" />
        <a-tab-pane key="2" title="处理记录" />
      </a-tabs>
      <list-searcher :searchList="searchList" v-model:searchForm="queryParam" @loadData="loadData" />
      <table-index :table="table" :rowKey="`id`" @loadData="loadData">
        <template #vehicleInfo="{ record }">
          <div class="car-msg">
            <div class="car-msg-left">
              <div class="col-text col-lic"> 设备类型：{{ record.vehicleTypeStr || '-' }} </div>
              <div class="col-text"> 设备品牌：{{ record.vehicleFirm || '-' }} </div>
              <div class="col-text">设备型号：{{ record.vehicleModelStr || '-' }}</div>
              <div class="col-text">供应商：{{ record.supplierName || '-' }}</div>
            </div>
          </div>
        </template>
        <template #carInfo="{ record }">
          <div class="car-msg">
            <div class="car-msg-left">
              <div class="col-text col-lic"> 车牌：{{ record.licenseNo || '-' }} </div>
              <div class="col-text"> 车型：{{ record.modelName || '-' }} </div>
            </div>
          </div>
        </template>
      </table-index>
    </div>
    <template #footer>
      <a-button @click="onClose">关闭</a-button>
    </template>
  </a-modal>
</template>

<script setup name="scjcwltips">
  import { ref, reactive, computed } from 'vue'
  import { getCarVehicleElectricFenceList } from '@/api/workplace.js'
  import { useTable, useFetchTableDataApi } from '@/hooks/table'
  //查询条件
  let queryParam = reactive({
    status: 0,
    rule: 2,
  })
  const searchList = computed(() => {
    return [
      {
        label: '所属门店',
        prop: 'siteId',
        type: 'remote-select',
        attrs: {
          type: 'site_listBystaff',
          popupContainer: '.modal-dialog-wrapper .remote-select-wrapper',
          params: {
            oldId: queryParam.siteId,
          },
        },
        change: (val) => {
          if (val) {
            queryParam.carId = ''
          }
        },
      },
      {
        label: '车牌号',
        prop: 'carId',
        type: 'remote-select',
        attrs: {
          type: 'car_licenseno_list',
          popupContainer: '.modal-dialog-wrapper .remote-select-wrapper',
          params: {
            siteId: queryParam.siteId,
          },
        },
      },
    ]
  })
  const columns = reactive([
    {
      columns: [
        { title: 'ID', dataIndex: 'id', width: 70 },
        { title: '设备sn/id', dataIndex: 'vehicleNum', width: 100 },
        { title: '设备信息', dataIndex: 'vehicleInfo', slotName: 'vehicleInfo', width: 100 },
        { title: '车辆信息', dataIndex: 'carInfo', slotName: 'carInfo', width: 240 },
        { title: '所属门店', dataIndex: 'siteName' },
        { title: '车辆状态', dataIndex: 'operateStatusName' },
        { title: '围栏名称', dataIndex: 'fenceName' },
        { title: '当前位置', dataIndex: 'lastAddress' },
        { title: '驶入围栏时长(小时)', dataIndex: 'hours', width: 170 },
        { title: '提醒时间', dataIndex: 'warningTime', width: 170 },
      ],
    },
    {
      columns: [
        { title: 'ID', dataIndex: 'id', width: 70 },
        { title: '设备编号', dataIndex: 'vehicleNum', width: 100 },
        { title: '设备信息', dataIndex: 'vehicleInfo', slotName: 'vehicleInfo', width: 100 },
        { title: '车辆信息', dataIndex: 'carInfo', slotName: 'carInfo', width: 240 },
        { title: '所属门店', dataIndex: 'siteName' },
        { title: '车辆状态', dataIndex: 'operateStatusName' },
        { title: '围栏名称', dataIndex: 'fenceName' },
        { title: '当前位置', dataIndex: 'lastAddress' },
        { title: '驶入围栏时长(小时)', dataIndex: 'hours', width: 170 },
        { title: '提醒时间', dataIndex: 'warningTime', width: 170 },
        { title: '处理人', dataIndex: 'handlerUserName' },
        { title: '处理时间', dataIndex: 'handlerTime', width: 170 },
      ],
    },
  ])
  // 待处理 - table 配置
  const table = useTable({
    tableHeight: 'calc(100vh - 400px)',
    columns: columns[0].columns,
  })
  // tabs 相关 开始
  const activeTabsKey = ref('1')
  const tabsChangeFn = (e) => {
    if (e === '1') {
      queryParam.status = 0
      table.columns = columns[0].columns
    } else {
      table.columns = columns[1].columns
      queryParam.status = 1
    }
    loadData()
  }

  // 列表接口调用
  const loadData = useFetchTableDataApi(table, queryParam, getCarVehicleElectricFenceList)
  // modal展示
  const visible = ref(false)
  let pageTlt = ref('')
  const open = (label) => {
    pageTlt = label
    visible.value = true
    loadData(1)
  }
  const onClose = () => {
    visible.value = false
    queryParam.status = 0
    queryParam.siteId = ''
    queryParam.carId = ''
    table.columns = columns[0].columns
  }
  defineExpose({
    open,
  })
</script>

<style lang="less" scoped>
  .car-msg {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .car-msg-left {
    margin-right: 10px;
  }
  .col-lic {
    color: #1d2129;
    font-size: 14px;
    font-weight: 600;
    margin-right: 16px;
  }
</style>
